/*
* Unit Test Bootstrap
* Autor: Tomasz Jaworski, 2018-2019
*
* Test dla zadania Histogram
* Autor testowanej odpowiedzi: Szymon Ptak
* Test wygenerowano automatycznie o 2019-08-22 14:39:52.586479
*
* Debug:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <setjmp.h>
#include <assert.h>
#define _RLDEBUG_API_
#include "unit_helper_v2.h"
#include "rdebug.h"
#include "tested_declarations.h"
#include "rdebug.h"
//
// Elementy globalne dla całego testu
//
//
// Test 1: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST1(void)
{
// informacje o teście
test_start(1, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {2, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0};
int output[] = {2, 2, 1, 1, 1, 2, 0, -2, 1, -1, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, 5, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [2, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 2: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST2(void)
{
// informacje o teście
test_start(2, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {4, 6, 3, 6, 3, 10, 9, 4, 8, 9, 6};
int output[] = {-1, 2, -1, -1, 2, 0, 1, 2, 0, 1, -2};
printf("#####START#####");
int res = create_histogram((float[]){6.407726, 7.879559, 10.402558, 4.771844, 10.793458, 8.755017, 8.846388, 0.229780, 9.246283, 10.494099, 1.459278, 1.261973, 5.401017, 4.794922, 9.920712, 8.361107, 3.967810, 7.495465, 0.790882, 3.031325, 9.366700, 4.594835, 9.797759, 2.376214, 10.657240, 9.073570, 6.037918, 6.035329, 5.303989, 6.097395, 5.666640, 5.361531, 1.080035, 1.824650, 7.310905, 6.784425, 5.289873, 8.015642, 0.767940, 5.958618, 5.313943, 6.217072, 3.415580, 2.235268, 5.199372, 1.987600, 6.653138, 6.242409, 9.068799, 1.546145, 9.086032, 8.149861, 0.755340, 3.918642, 7.701922, 9.359540, 5.386907, 8.574876, 9.339332, 8.644161, 10.701943, 5.473253, 3.214153, 3.293085, 10.360329, 8.988244, 2.219719, 6.252553}, 68, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [4, 6, 3, 6, 3, 10, 9, 4, 8, 9, 6]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 3: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST3(void)
{
// informacje o teście
test_start(3, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {13, 10, 10, 7, 14, 8, 19, 16, 17, 12, 12};
int output[] = {-1, -2, 0, 0, 1, -1, 1, -2, -2, -2, 1};
printf("#####START#####");
int res = create_histogram((float[]){10.009170, 6.259468, 0.835052, 1.641707, 4.989624, 1.694516, 5.132234, 9.687642, 4.765445, 10.117847, 9.979220, 3.269232, 8.422829, 2.974793, 8.955186, 7.280910, 6.527964, 10.552025, 9.348634, 5.877540, 10.755626, 8.431764, 10.695781, 7.648720, 5.553985, 0.514502, 8.482657, 1.861201, 9.869589, 7.313095, 5.723101, 1.629314, 3.356095, 7.641699, 7.477487, 7.642554, 8.062867, 3.496447, 7.023728, 9.746197, 4.840523, 6.941373, 6.069427, 4.117833, 4.554499, 10.601889, 2.113441, 8.863596, 9.020980, 1.481398, 6.012840, 2.363884, 2.702654, 2.207523, 4.889324, 1.853217, 7.517669, 8.702098, 10.706953, 9.026755, 9.246175, 9.172053, 6.625317, 8.737825, 7.943558, 1.874067, 9.304714, 7.051504, 8.872116, 3.183699, 0.599600, 0.363317, 4.214120, 0.633304, 8.722039, 5.765186, 6.896202, 4.727991, 6.634798, 4.125822, 6.436584, 4.077207, 6.868738, 6.973207, 4.782158, 6.561481, 6.511325, 10.106267, 2.466381, 0.024817, 8.481523, 0.702741, 0.073356, 2.215358, 0.045023, 6.840321, 8.922734, 7.757802, 0.306966, 3.143595, 6.844356, 8.740290, 6.315091, 8.452291, 3.323540, 0.161113, 10.681810, 7.045575, 10.404718, 7.535486, 1.822128, 5.330453, 6.614618, 5.439854, 1.993055, 7.419053, 8.985360, 7.282120, 6.704629, 8.364046, 9.551327, 5.061497, 4.958516, 4.129753, 7.162060, 9.104632, 0.178040, 1.064577, 2.134375, 0.446297, 3.829535, 8.344496, 10.031061, 6.019635, 2.482023, 4.126602, 10.021579, 2.931628}, 138, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [13, 10, 10, 7, 14, 8, 19, 16, 17, 12, 12]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 4: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST4(void)
{
// informacje o teście
test_start(4, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0};
int output[] = {1, -2, -2, 0, 2, -2, -2, -2, -2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){-1.495237, -6.754772, -3.545173, 5.559797, -5.995378, -9.056444, -0.917119, -7.631384, 3.853611}, 9, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 5: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST5(void)
{
// informacje o teście
test_start(5, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {4, 3, 2, 2, 2, 4, 0, 3, 2, 5, 0};
int output[] = {2, 0, 2, -1, -1, 2, 0, 1, -1, 2, -2};
printf("#####START#####");
int res = create_histogram((float[]){-4.830156, 0.664367, 8.223148, -8.658458, -8.865792, -4.947816, 4.823427, 4.532761, 5.604382, 9.794981, -6.548414, -2.292325, 9.075233, 0.585363, 3.569781, -4.937413, 7.151026, -9.594850, 5.118001, -8.701071, 5.899546, 9.165214, -1.758713, 1.438438, 2.095971, -4.200740, -6.972914, 9.639254, 7.664862, -8.871531, 5.767714, 8.463985, -4.569647, -9.339798, 2.984813, 7.022325, -4.753264, -8.040415, -3.472994, -7.214161, -7.926868, -4.005451, 0.932052, 1.751531, 1.721741, 3.590466, -5.542680, -5.629237, -1.557989, 0.186749, 9.247736, -3.654722, -7.641550}, 53, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [4, 3, 2, 2, 2, 4, 0, 3, 2, 5, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 6: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST6(void)
{
// informacje o teście
test_start(6, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {5, 2, 2, 4, 4, 5, 3, 2, 1, 2, 1, 4, 1, 3, 3, 3, 1, 3, 3, 2, 0};
int output[] = {1, 1, 0, 0, -1, -2, -1, 1, 2, -1, 0, -2, -2, 2, -2, -1, 2, -1, 2, -1, 2};
printf("#####START#####");
int res = create_histogram((float[]){15.830652, 19.219014, 11.244898, 2.677010, 7.347770, 4.026470, 8.749616, 18.233438, 5.916041, 18.485151, 12.164072, 5.840749, 3.809157, 3.238112, 17.464461, 7.790933, 1.631086, 6.608522, 11.840181, 13.816168, 1.280030, 0.747208, 4.726812, 0.775804, 15.699639, 5.208295, 17.421247, 11.895023, 10.695037, 15.642218, 16.180937, 4.485997, 0.715700, 18.874611, 14.026967, 6.070168, 5.443011, 5.914377, 14.628063, 6.283159, 19.584065, 0.236821, 13.551998, 9.040854, 17.453997, 14.800577, 4.570275, 11.490413, 3.283861, 3.610078, 0.092450, 2.352116, 9.793846, 13.039742}, 54, output, 21);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 21; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [5, 2, 2, 4, 4, 5, 3, 2, 1, 2, 1, 4, 1, 3, 3, 3, 1, 3, 3, 2, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 21; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 7: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST7(void)
{
// informacje o teście
test_start(7, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {14, 12, 15, 21, 20, 11, 16, 13, 14, 13, 14, 14, 17, 16, 18, 16, 19, 20, 16, 21, 11, 15, 10, 16, 14, 9, 13, 17, 16, 22, 20, 12, 21, 20, 14, 21, 13, 12, 16, 10, 23, 17, 16, 18, 13, 8, 12, 19, 15, 19, 12, 22, 14, 13, 13, 12, 15, 14, 16, 21, 14, 9, 14, 0};
int output[] = {2, 2, 2, 1, -1, 1, 0, 1, 1, 2, -2, 0, 0, 2, 2, 0, 1, -2, 2, 1, 0, 2, -2, 2, -2, 2, -2, -1, -1, 2, -1, -2, 1, 1, 0, 1, -2, 1, -1, 2, -2, 2, 1, 1, -2, 1, 1, -2, 0, 0, 2, -1, -1, -2, 0, -1, -1, -2, 2, 2, -1, 2, 2, 1};
printf("#####START#####");
int res = create_histogram((float[]){28.085282, 21.660877, 32.050078, 35.016608, 34.692729, 5.996193, 29.875155, 17.456368, 24.095264, 10.853787, 43.483018, 47.331295, 26.168291, 55.945088, 7.041458, 9.182943, 35.041428, 0.377587, 17.860677, 41.710745, 43.013956, 61.073731, 29.239989, 13.075730, 59.128137, 59.426436, 31.977316, 1.643509, 16.451254, 29.182214, 3.761475, 1.200376, 33.780232, 2.103771, 21.183652, 57.530487, 59.758311, 38.857410, 33.458057, 48.517262, 11.679941, 50.449393, 13.169251, 28.078793, 46.752323, 31.174077, 26.695125, 39.055079, 51.618173, 21.448867, 55.703113, 30.671436, 40.342363, 10.292388, 52.955966, 40.288638, 27.272275, 17.216214, 25.274645, 21.260796, 10.032929, 57.228921, 19.469199, 48.067781, 47.599993, 26.808903, 57.752809, 16.865036, 13.710289, 39.085950, 35.973379, 51.969743, 0.775079, 41.134192, 37.508694, 7.837745, 33.853106, 48.198690, 16.370651, 21.938379, 62.444170, 42.109573, 15.415693, 40.059850, 46.708786, 59.933920, 47.484757, 39.946723, 47.472120, 54.223467, 32.864047, 32.020309, 15.975393, 12.292936, 40.992219, 51.619651, 40.399966, 14.705771, 4.635849, 52.837188, 2.940671, 35.406450, 23.885952, 56.634910, 23.985124, 56.986145, 12.387795, 6.645904, 51.327340, 10.145932, 8.032421, 56.872505, 41.619428, 25.810323, 42.412874, 62.253120, 23.547883, 24.585754, 9.207765, 34.446225, 50.227456, 6.584824, 31.943070, 13.040978, 11.094743, 51.270769, 1.984904, 10.109029, 32.625644, 55.518405, 37.569287, 56.271867, 51.043062, 24.660699, 9.600589, 11.163180, 56.625602, 17.748772, 53.064307, 26.766273, 23.212232, 26.686082, 28.506360, 60.236953, 29.564445, 48.579389, 29.504079, 7.213822, 33.405301, 0.787111, 27.546616, 54.605857, 1.001124, 50.922305, 4.102936, 20.971979, 20.536780, 29.893577, 24.938862, 27.884293, 5.082686, 41.713518, 29.808781, 1.103425, 24.624212, 19.621637, 3.687282, 29.215461, 20.575587, 43.193699, 58.409002, 3.142114, 51.911333, 55.203750, 36.212716, 33.923455, 17.816596, 58.012070, 54.903704, 29.961734, 35.815393, 56.055922, 1.365221, 10.285211, 51.791682, 53.275383, 10.555154, 62.412785, 17.058324, 20.992703, 52.659973, 62.957923, 34.645894, 18.212088, 14.045450, 6.229384, 5.355444, 22.194539, 6.491168, 28.136992, 37.364494, 17.259456, 26.706234, 34.740331, 26.416735, 17.157892, 6.858129, 31.623595, 39.853271, 56.973328, 38.558162, 52.494498, 4.125744, 10.098895, 51.340299, 51.515546, 41.398919, 16.496451, 36.266719, 40.393596, 58.326475, 48.804993, 9.214460, 39.719981, 31.699416, 49.269363, 16.848313, 32.300123, 40.343147, 16.045937, 40.189303, 45.977610, 22.072680, 56.866062, 32.714516, 9.410984, 27.507491, 44.415919, 45.106805, 30.399268, 62.054718, 29.786545, 35.697554, 30.988329, 7.533593, 38.713259, 57.427794, 41.089914, 0.978482, 38.318030, 7.905685, 37.453258, 15.853303, 24.437340, 35.662837, 21.843103, 39.838112, 16.535740, 57.498460, 38.670545, 12.431756, 52.198981, 44.776077, 47.639170, 3.139867, 14.116823, 38.438670, 31.903337, 14.520314, 57.555036, 14.032980, 35.630354, 24.329504, 30.115547, 44.654197, 30.636493, 11.444339, 19.024869, 39.176161, 6.856599, 24.367350, 47.249971, 14.271061, 9.448419, 11.719061, 14.975711, 3.111410, 15.554109, 11.141130, 23.718136, 12.542037, 47.900474, 44.569604, 35.757686, 7.718831, 18.144164, 0.716084, 26.963674, 20.007857, 6.194140, 9.003896, 9.414360, 38.177534, 16.998573, 54.851915, 12.371076, 36.291858, 24.717603, 44.932251, 4.940257, 61.023266, 28.648788, 53.753012, 48.281785, 47.757794, 58.549589, 47.177276, 43.501131, 18.584622, 15.415206, 20.797902, 59.197362, 48.837000, 35.655761, 3.550188, 42.950604, 11.123613, 31.068230, 24.554983, 14.280398, 16.256352, 44.915729, 34.315714, 50.173442, 11.555091, 23.399324, 35.331749, 55.088837, 19.128337, 7.069576, 30.647389, 31.453641, 46.459296, 56.091641, 21.673008, 62.902712, 7.737934, 22.127822, 46.214387, 14.899336, 43.767981, 24.703069, 28.365248, 49.309795, 33.814419, 24.016710, 33.730165, 27.197341, 4.722383, 16.737904, 3.543281, 4.505089, 36.786072, 37.472137, 40.016659, 20.777230, 3.389792, 31.987274, 35.279447, 42.509515, 2.750297, 61.386215, 57.030776, 1.252033, 58.950243, 18.036029, 59.304765, 47.249008, 55.293311, 29.332592, 53.888111, 2.061213, 2.452493, 4.516085, 5.479325, 8.903224, 40.915284, 2.145554, 62.465908, 3.105238, 1.901217, 18.881603, 15.686399, 12.575199, 9.410264, 43.447781, 27.621987, 20.040619, 8.670807, 39.543158, 21.989681, 40.738920, 17.572400, 43.579480, 59.942663, 14.676146, 19.259166, 17.413242, 41.892315, 53.614872, 11.146061, 8.734605, 32.760974, 38.727786, 18.602104, 35.882080, 54.490971, 5.975373, 29.897821, 17.048923, 12.236935, 43.960766, 30.059995, 34.025515, 46.471335, 58.488326, 42.440288, 14.290134, 38.890749, 12.157185, 27.244142, 20.559335, 42.508902, 15.029607, 28.405563, 8.909010, 30.751733, 10.815185, 58.491281, 56.771426, 8.279992, 19.151746, 18.708020, 38.650495, 6.220906, 40.721939, 59.996460, 14.478954, 5.520172, 35.554182, 2.872499, 13.174715, 46.366744, 13.820762, 0.670052, 30.048417, 49.052705, 55.012780, 43.228591, 23.670111, 24.681103, 30.699666, 29.665254, 53.704762, 6.032157, 42.068180, 0.503348, 35.800593, 47.572957, 62.939296, 0.176230, 49.060854, 11.842874, 18.098202, 27.129738, 42.875505, 19.858222, 33.525677, 60.031812, 62.956641, 54.262770, 16.622361, 54.491782, 48.423271, 23.125546, 49.822859, 47.047847, 13.822308, 21.456379, 62.534173, 62.642601, 32.031415, 49.171445, 34.247461, 48.522064, 53.124305, 12.960150, 27.298438, 15.771963, 58.946551, 43.723502, 4.141715, 35.666255, 32.905101, 38.292311, 50.982151, 57.593684, 44.340146, 36.890017, 32.483324, 17.506722, 15.357295, 8.504282, 32.248356, 26.785260, 36.463405, 49.285183, 41.097649, 3.707173, 60.680928, 26.708393, 24.015233, 19.421138, 25.862280, 22.578115, 19.366211, 42.141560, 58.409226, 46.879019, 13.913529, 3.542612, 6.418990, 54.650243, 22.253583, 36.531706, 60.581982, 7.140166, 56.402954, 49.144291, 32.541069, 11.437411, 7.982257, 22.257031, 53.352518, 16.399376, 62.648507, 51.612680, 3.011453, 50.204719, 12.838429, 16.329377, 14.567299, 34.587379, 50.887199, 2.784303, 41.264756, 5.803098, 5.144734, 42.637126, 28.986468, 7.460582, 36.127887, 3.721622, 27.638336, 43.522889, 29.996540, 52.486160, 44.789975, 18.130577, 30.786472, 40.580830, 4.419731, 28.531197, 14.623223, 59.987854, 49.370334, 60.893565, 49.488193, 12.525939, 40.305147, 55.295460, 53.007145, 25.909542, 57.046378, 49.442902, 58.796604, 52.150919, 2.852766, 43.244830, 32.383731, 29.046144, 16.782038, 8.780286, 58.730098, 40.937444, 29.614753, 38.447728, 61.381550, 41.252397, 39.847250, 49.592957, 27.518846, 17.300039, 18.675565, 30.383394, 8.071275, 55.345104, 51.776293, 50.899398, 6.205373, 23.532394, 1.978363, 46.870273, 54.050641, 1.564550, 13.720329, 17.887459, 49.363409, 36.769750, 48.542614, 13.860953, 59.721973, 57.875766, 37.590326, 13.452477, 42.434054, 33.857537, 12.470794, 55.929290, 33.304216, 23.543349, 51.031328, 19.518560, 10.269510, 46.354544, 34.701437, 35.975905, 43.862067, 7.217254, 9.496618, 50.443478, 13.832253, 44.283772, 21.269919, 28.798411, 53.930819, 43.769916, 2.507425, 11.457886, 2.963617, 48.501951, 59.103716, 18.725684, 49.587505, 16.371181, 46.890761, 19.781006, 59.770648, 55.063490, 20.446038, 37.357100, 55.156642, 32.902589, 34.923669, 60.031452, 53.245201, 47.286263, 31.327488, 31.590762, 61.822184, 30.099850, 2.840262, 45.818347, 60.809025, 19.448711, 51.760982, 33.257761, 15.117246, 59.300881, 56.091024, 40.170892, 0.630187, 56.798080, 3.745279, 41.460985, 61.155804, 10.017335, 35.870485, 29.760684, 22.135265, 14.086966, 25.981127, 35.221220, 14.515799, 44.160893, 38.570335, 50.660269, 27.101301, 3.994282, 25.909198, 18.026609, 51.841979, 15.215843, 23.194283, 3.733833, 35.401489, 41.651804, 18.124007, 15.635322, 0.948945, 17.749949, 52.787148, 36.248976, 13.151791, 47.550276, 28.662300, 16.451650, 19.151922, 22.761132, 4.948488, 8.988739, 58.877039, 4.909799, 4.106012, 28.963813, 51.567685, 4.836546, 38.891688, 48.121242, 16.634514, 32.970220, 6.230239, 25.168883, 37.618178, 17.846913, 38.308255, 0.093847, 41.055899, 49.915992, 13.960253, 19.111921, 30.060606, 29.671558, 40.907594, 45.408390, 47.347736, 62.286624, 58.284736, 9.126882, 37.758215, 31.205824, 17.198001, 54.363629, 33.286930, 57.812764, 45.496302, 27.395271, 34.176109, 51.978364, 32.790520, 15.933103, 61.310360, 29.789775, 28.041438, 27.333341, 41.891421, 60.921728, 54.726067, 19.243568, 19.142256, 50.272309, 58.464597, 48.820482, 60.723881, 6.510768, 8.116791, 41.574546, 18.809244, 33.683640, 41.180301, 47.090811, 61.556098, 18.954823, 23.535303, 27.615595, 1.017690, 30.633788, 30.861181, 60.520295, 30.566166, 47.737479, 12.936622, 4.864757, 43.705366, 22.318710, 46.944945, 29.756934, 44.362759, 59.970933, 51.408560, 42.046850, 29.513974, 34.059231, 50.698796, 44.503796, 37.637227, 15.542752, 18.470543, 38.724247, 59.621007, 40.205011, 46.700401, 34.518593, 19.788353, 53.722146, 0.258210, 29.666201, 34.917925, 57.255458, 44.050798, 4.234973, 3.385120, 17.845388, 2.482044, 28.229981, 8.726235, 14.135081, 39.333295, 47.595138, 43.841330, 19.832809, 30.679390, 52.559671, 40.278857, 43.538751, 30.778072, 3.149832, 33.233682, 51.706655, 59.181136, 0.450720, 32.668736, 2.655943, 4.043245, 23.427145, 51.272960, 3.822623, 48.150578, 23.914186, 10.775719, 49.801271, 26.122845, 30.314909, 52.689205, 27.585922, 33.580919, 10.787466, 36.790431, 33.910889, 26.980334, 3.995419, 11.358664, 59.371792, 8.183449, 45.455521, 43.511607, 57.702677, 33.893621, 21.959502, 40.452733, 58.299336, 62.964178, 32.783018, 42.810844, 59.682590, 45.280895, 42.933819, 6.226984, 16.703965, 25.495012, 28.459387, 28.450966, 11.238317, 41.498198, 52.360220, 6.604319, 5.975689, 1.938127, 60.875757, 4.692907, 23.503552, 2.250164, 15.477730, 36.142706, 19.299084, 26.012365, 56.105951, 35.697419, 9.703606, 20.953385, 5.747678, 33.623425, 23.986021, 12.300288, 15.464159, 33.408948, 48.283186, 7.552185, 56.844862, 60.338734, 51.423638, 0.920673, 19.333823, 12.578620, 40.766487, 8.737874, 17.086693, 37.228989, 61.850459, 21.747825, 32.849814, 54.245926, 36.311503, 60.248051, 49.009518, 60.999947, 42.062792, 13.219127, 16.478875, 52.793184, 19.455207, 22.381122, 58.283417, 9.138133, 12.991130, 59.044910, 4.364057, 57.138489, 59.233444, 40.010587, 51.591042, 54.949508, 42.965274, 12.270258, 6.866835, 4.034542, 3.457268, 32.610710, 17.733212, 49.851310, 13.095313, 49.546357, 4.417480, 45.863705, 52.389152, 59.185883, 10.429762, 40.398439, 37.958966, 47.681703, 53.576766, 25.529364, 14.195330, 52.352353, 21.169868, 27.835477, 5.251907, 21.098940, 33.204105, 32.705273, 21.906017}, 971, output, 64);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 64; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [14, 12, 15, 21, 20, 11, 16, 13, 14, 13, 14, 14, 17, 16, 18, 16, 19, 20, 16, 21, 11, 15, 10, 16, 14, 9, 13, 17, 16, 22, 20, 12, 21, 20, 14, 21, 13, 12, 16, 10, 23, 17, 16, 18, 13, 8, 12, 19, 15, 19, 12, 22, 14, 13, 13, 12, 15, 14, 16, 21, 14, 9, 14, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 64; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 8: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST8(void)
{
// informacje o teście
test_start(8, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {11, 8, 10, 7, 11, 9, 7, 13, 8, 2};
int output[] = {1, -1, -2, 2, 1, -2, 0, 1, -2, -2};
printf("#####START#####");
int res = create_histogram((float[]){5.881584, 7.689706, 5.799645, 6.798359, 3.575384, 8.946210, 7.625983, 4.853607, 4.807154, 8.186755, 3.200029, 0.129813, 4.656316, 3.287815, 7.119646, 4.458621, 3.581910, 5.242923, 10.342199, 7.474731, 2.638168, 6.631599, 6.765608, 8.229740, 7.823955, 4.867304, 0.147408, 2.691725, 10.201411, 5.117992, 1.537863, 3.735537, 4.508182, 9.440414, 10.531046, 1.100818, 7.038700, 8.215464, 1.700720, 10.605184, 4.938324, 2.712159, 0.249943, 4.474532, 1.573654, 10.436760, 3.882538, 0.058736, 2.637672, 7.951393, 2.911452, 7.792134, 2.744772, 5.237740, 0.939432, 6.871826, 5.421224, 4.934645, 1.642704, 5.796707, 5.506053, 2.511124, 8.866657, 0.161273, 2.615344, 5.831834, 1.215542, 0.739527, 1.020945, 7.836844, 0.642562, 2.859703, 6.158134, 10.675757, 4.042532, 1.233886, 10.500732, 8.150756, 7.619023, 0.666952, 7.042023, 10.927452, 7.176781, 8.989334, 9.933952, 7.084712, 0.465889, 10.911461, 3.179796, 0.123336, 2.115144, 6.842482, 8.706504, 6.042538, 4.557091}, 95, output, 10);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 10; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [11, 8, 10, 7, 11, 9, 7, 13, 8, 2]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 10; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 9: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST9(void)
{
// informacje o teście
test_start(9, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
int output[] = {-2, 2, -1, -1, 1, 0, 1, 1, 0, 0, -2};
printf("#####START#####");
int res = create_histogram((float[]){6.006469}, 1, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 10: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST10(void)
{
// informacje o teście
test_start(10, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {10};
int output[] = {-1};
printf("#####START#####");
int res = create_histogram((float[]){5.765664, 10.837312, 3.961478, 6.055695, 4.051140, 1.273092, 2.702224, 5.050273, 9.866214, 1.850711, 7.620615, 1.763215, 8.379959, 8.153137, 5.241479, 0.069969, 2.907955, 1.729969, 8.460296, 2.149443, 0.908840, 10.880231, 2.006989, 8.760909, 8.297603, 2.667351, 10.627640, 7.225665, 1.776964, 6.424674, 0.018535, 6.166718, 0.759137, 6.741575, 2.957825, 0.827642, 7.909821, 2.795849, 0.918825, 2.517544, 2.130485, 6.518327, 6.084747, 1.342468, 10.762672, 8.744106, 4.025454, 4.595872, 9.565002, 8.826676, 4.630772, 9.409888, 1.728743, 4.544100, 1.074514, 10.278106, 7.429060, 10.717877, 9.584248, 3.872379, 8.648803, 4.048136, 4.565149, 9.109035, 4.681098, 1.283213, 1.900570, 8.647911, 4.754252, 9.822430, 0.813426, 9.434695, 9.510549, 8.791511, 7.287448, 0.375265, 2.587655, 9.087088, 0.646850, 10.497103, 9.159185, 2.687692, 4.717014, 2.210614, 6.628374, 4.408165, 4.362748, 9.359473, 4.190420, 9.178370, 8.801943, 10.712549, 1.138637, 10.423692, 9.256525, 6.948785, 8.374081, 9.472183, 0.487426, 8.245493}, 100, output, 1);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 1; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [10]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 1; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 11: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST11(void)
{
// informacje o teście
test_start(11, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, 16, NULL, 12);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 12: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST12(void)
{
// informacje o teście
test_start(12, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {0, -1, 0, -2, 1, -2, -2, 0, 2, 0, -1};
printf("#####START#####");
int res = create_histogram(NULL, 17, output, 13);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 13: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST13(void)
{
// informacje o teście
test_start(13, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {0, -1, 0, -2, 1, -2, -2, 0, 2, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, 0, output, 20);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 14: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST14(void)
{
// informacje o teście
test_start(14, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {0, -1, 0, -2, 1, -2, -2, 0, 2, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, 14, output, 0);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 15: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST15(void)
{
// informacje o teście
test_start(15, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {0, -1, 0, -2, 1, -2, -2, 0, 2, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, -18, output, 10);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 16: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST16(void)
{
// informacje o teście
test_start(16, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {0, -1, 0, -2, 1, -2, -2, 0, 2, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){9.405139, 9.663794, 0.981388, 1.253263, 0.165902}, 20, output, -15);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 17: Sprawdzanie poprawności działania funkcji display
//
void UTEST17(void)
{
// informacje o teście
test_start(17, "Sprawdzanie poprawności działania funkcji display", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int tab[] = {2, 7, 8, 0, -1, 1, 7};
//-------------1-----------------------
printf("\n***TEST 1***\n\n");
printf("***START***\n");
display_vector(tab, 0);
printf("***END***\n");
//-------------2-----------------------
printf("\n***TEST 2***\n\n");
printf("***START***\n");
display_vector(tab, -7);
printf("***END***\n");
//-------------3-----------------------
printf("\n***TEST 3***\n\n");
printf("***START***\n");
display_vector(tab, 7);
printf("***END***\n");
//-------------4-----------------------
printf("\n***TEST 4***\n\n");
printf("***START***\n");
display_vector(tab, 7 - 1);
printf("***END***\n");
onerror_terminate(); // przerwanie wszystkich testów jednostkowych (np. coś jest mocno nie tak z kodem)
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 18: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST18(void)
{
// informacje o teście
test_start(18, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 6;
const float expected_array[] = {3.000000, -5.000000, -3.000000, -1.000000, 4.000000, -8.000000, 0.000000};
float dest[7];
int result = read_vector_float(dest, 7, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [3.000000, -5.000000, -3.000000, -1.000000, 4.000000, -8.000000, 0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 19: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST19(void)
{
// informacje o teście
test_start(19, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 11;
const float expected_array[] = {-4.000000, -6.000000, 3.000000, -2.000000, -8.000000, 8.000000, 1.000000, -1.000000, -2.000000, 0.000000, -2.000000, -5.000000};
float dest[12];
int result = read_vector_float(dest, 12, -5);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-4.000000, -6.000000, 3.000000, -2.000000, -8.000000, 8.000000, 1.000000, -1.000000, -2.000000, 0.000000, -2.000000, -5.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 20: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST20(void)
{
// informacje o teście
test_start(20, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 0;
const float expected_array[] = {0.000000};
float dest[5];
int result = read_vector_float(dest, 5, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 21: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST21(void)
{
// informacje o teście
test_start(21, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 8;
const float expected_array[] = {-7.000000, 10.000000, -8.000000, 2.000000, -10.000000, -7.000000, 4.000000, -7.000000};
float dest[8];
int result = read_vector_float(dest, 8, -9);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-7.000000, 10.000000, -8.000000, 2.000000, -10.000000, -7.000000, 4.000000, -7.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 22: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST22(void)
{
// informacje o teście
test_start(22, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[8];
printf("#####START#####");
int result = read_vector_float(dest, 0, -5);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 23: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST23(void)
{
// informacje o teście
test_start(23, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[10];
printf("#####START#####");
int result = read_vector_float(dest, -10, -9);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 24: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST24(void)
{
// informacje o teście
test_start(24, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
printf("#####START#####");
int result = read_vector_float(NULL, -5, 2);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
enum run_mode_t { rm_normal_with_rld = 0, rm_unit_test = 1, rm_main_test = 2 };
int __wrap_main(volatile int _argc, char** _argv, char** _envp)
{
int volatile vargc = _argc;
char ** volatile vargv = _argv, ** volatile venvp = _envp;
volatile enum run_mode_t run_mode = rm_unit_test; // -1
volatile int selected_test = -1;
if (vargc > 1)
{
char* smode = strtok(vargv[1], ",");
char* stest = strtok(NULL, "");
char *errptr = NULL;
run_mode = (enum run_mode_t)strtol(smode, &errptr, 10);
if (*errptr == '\x0')
{
memmove(vargv + 1, vargv + 2, sizeof(char*) * (vargc - 1));
vargc--;
if (stest != NULL)
{
int val = (int)strtol(stest, &errptr, 10);
if (*errptr == '\x0')
selected_test = val;
}
}
}
// printf("runmode=%d; selected_test=%d\n", run_mode, selected_test);
// inicjuj testy jednostkowe
unit_test_init(run_mode, "unit_test_v2.c");
test_limit_init();
rldebug_set_reported_severity_level(MSL_FAILURE);
if (run_mode == rm_normal_with_rld)
{
// konfiguracja ograniczników
rldebug_reset_limits();
// uruchom funkcję main Studenta a potem wyświetl podsumowanie sterty i zasobów
volatile int ret_code = rdebug_call_main(tested_main, vargc, vargv, venvp);
rldebug_reset_limits();
int leaks_detected = rldebug_show_leaked_resources(0);
if (leaks_detected)
raise(SIGHEAP);
return ret_code;
}
if (run_mode == rm_unit_test)
{
test_title("Testy jednostkowe");
void (*pfcn[])(void) =
{
UTEST1, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST2, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST3, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST4, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST5, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST6, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST7, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST8, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST9, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST10, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST11, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST12, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST13, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST14, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST15, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST16, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST17, // Sprawdzanie poprawności działania funkcji display
UTEST18, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST19, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST20, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST21, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST22, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST23, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST24, // Sprawdzanie poprawności działania funkcji read_vector_float
NULL
};
for (int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx]();
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(24); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
if (run_mode == rm_main_test)
{
test_title("Testy funkcji main()");
void (*pfcn[])(int, char**, char**) =
{
NULL
};
for (volatile int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx](vargc, vargv, venvp);
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(0); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
printf("*** Nieznana wartość RunMode: %d", (int)run_mode);
abort();
}